package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Category;
import com.cskaoyan.bean.category.bo.CategoryCreateBo;
import com.cskaoyan.bean.category.bo.CategoryDeleteBo;
import com.cskaoyan.bean.category.bo.CategoryUpdateBo;
import com.cskaoyan.bean.category.vo.CategoryL1Vo;
import com.cskaoyan.bean.category.vo.CategoryListVo;
import com.cskaoyan.service.CategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wangdezhao
 * @date 2021/6/5
 * @description
 */
@RestController
@RequestMapping("admin/category")
public class AdminCategoryController {
    @Autowired
    CategoryService categoryService;

    /**
     * 输出所有商品类目
     * @return
     */

    @RequestMapping("list")
    public BaseRespVo list(){
        List<CategoryListVo> categoryListVos = categoryService.getCategoryList();
        return BaseRespVo.ok(categoryListVos);
    }

    /**
     * 主类目 id 名称
     * @return
     */
    @RequestMapping("l1")
    public BaseRespVo l1(){
        List<CategoryL1Vo> categoryL1VoList = categoryService.getL1List();
        return BaseRespVo.ok(categoryL1VoList);
    }

    /**
     * 添加类目
     * @param createBo
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody CategoryCreateBo createBo){
        Integer effectedRows = categoryService.createCategory(createBo);
        return BaseRespVo.ok("成功插入"+effectedRows+"条数据");
    }

    /**
     * 更新类目
     * @param updateBo
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody CategoryUpdateBo updateBo) {
        Integer effectedRows = categoryService.updateCategory(updateBo);
        return BaseRespVo.ok("成功修改"+effectedRows+"条数据");
    }

    /**
     * 删除类目 假删除
     */
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody CategoryDeleteBo deleteBo){
        Integer effectedRows = categoryService.deleteCategory(deleteBo);
        return BaseRespVo.ok("成功删除"+effectedRows+"条数据");
    }
}
